package com.itheima.reggie.controller;

import com.itheima.reggie.entity.ShoppingCart;
import com.itheima.reggie.service.ShoppingCartService;
import com.itheima.reggie.utils.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/shoppingCart")
public class ShoppingCartController {

    @Resource
    private ShoppingCartService shoppingCartService;

    /**
     * 向购物车添加商品
     * @param shoppingCart 封装商品信息
     * @return ShoppingCart类型的通用返回结果
     */
    @PostMapping("/add")
    public Result<ShoppingCart> addShoppingCart(@RequestBody ShoppingCart shoppingCart){
        return shoppingCartService.addShoppingCart(shoppingCart);
    }

    /**
     * 获取当前用户购物车中的商品列表
     * @return 商品列表类型的通用返回结果
     */
    @GetMapping("/list")
    public Result<List<ShoppingCart>> getShoppingCartList(){
        return shoppingCartService.getShoppingCartList();
    }

    /**
     * 清空当前用户的购物车
     * @return String类型的通用返回结果
     */
    @DeleteMapping("/clean")
    public Result<String> cleanShoppingCart(){
        return shoppingCartService.cleanShoppingCart();
    }
}
